package
{
	import com.xcopy.GameSound;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.media.Sound;

	public class Slot25Table extends Slot25Standard
	{
		public var machine:Slot25Machine = new Slot25Machine(this);
		public var lobby:Slot25Lobby     = new Slot25Lobby(this);
		public var menu:Slot25Menu       = new Slot25Menu(this);
		public var alert:Slot25Messenger = new Slot25Messenger(this);
		public var rule:Slot25Rule       = new Slot25Rule(this);
		public var radio:GameSound       = new GameSound();
		public var alreadyDone:Boolean   = false;
		public var girl:MovieClip;
		protected var _music:String      = '';

		public function set music(s:String):void
		{
			if (_music == s)
			{
				return;
			}
			_music = s;
			if (s == '')
			{
				stopMusic();
			}
			else
			{
				playMusic(s);
			}
		}

		public function get music():String
		{
			return _music;
		}

		public function Slot25Table(r:* = null)
		{
			super(r);
			alreadyDone = false;
		}

		override public function set clip(mc:MovieClip):void
		{
			super.clip = mc;
			machine.clip = clip.oMachine;
			lobby.clip = clip.oLobby;
			if (lobby.clip.hasOwnProperty('oGirl'))
			{
				girl = lobby.clip.oGirl;
			}
			menu.clip = clip.oMenu;
			alert.clip = clip.oMsn;
			rule.clip = clip.oManual;
			lobby.enable();
			menu.enable();
			lobby.clearTable();
		}

		public function addMusic(ID:String, sound:Sound):void
		{
			radio.addMusic(ID, sound);
		}

		public function addSound(ID:String, sound:Sound):void
		{
			radio.addSound(ID, sound);
		}

		public function playMusic(name:String, isLoop:Boolean = true):void
		{
			radio.playMusic(name, isLoop);
		}

		public function playSound(name:String, id:String = ''):void
		{
			radio.playSound(name, id);
		}

		public function stopMusic():void
		{
			radio.stopMusic();
		}

		public function stopSound(id:String = ''):void
		{
			radio.stopSound(id);
		}

		public function getInTable(type:Number, num:Number, ret:Number):void
		{
			switch (ret)
			{
				case 1:
				{
					machine.onMachine(num);
					menu.onMachine();
					lobby.disable();
					girlPlay(false);
					lobby.requestPage();
					break;
				}
				default:
				{
					machine.offMachine();
					menu.onMachine();
					lobby.requestPage();
					break;
				}
			}
		}

		public function getOutTable(type:Number, num:Number, ret:Number):void
		{
			switch (ret)
			{
				case 1:
				{
					machine.offMachine();
					menu.offMachine();
					machine.disable();
					lobby.enable();
					lobby.requestPage();
					girlPlayDelay(0.05);
					break;
				}
			}
		}

		public function girlPlayDelay(time:Number):void
		{
			addCaller(this, {time: time, count: 1, onUpdate: girlPlay});
		}

		public function girlPlay(bool:Boolean = true):void
		{
			if (girl != null)
			{
				if (bool)
				{
					girl.gotoAndPlay('Normal');
				}
				else
				{
					girl.gotoAndStop('Normal');
				}
			}
		}
	}
}
